package club.vann.kafka.mock.common.http;

import lombok.Getter;
import lombok.Setter;

/** Http响应信息结构，主要用于与前端系统信息交互 */
public class HttpResponse {
  /** 响应状态 */
  @Getter @Setter private HttpStatus status;

  /** 响应信息 */
  @Getter @Setter private String message;

  /** 响应结果数据 */
  @Getter @Setter private Object data;

  /** 用于支持分页 */
  /** 当前页 */
  @Getter private int curPage;

  /** 每页数据量 */
  @Getter private int pageSize;

  /** 总记录数 */
  @Getter private long totalCount;

  /** 总页数 */
  @Getter private long totalPage;

  public HttpResponse() {}

  public HttpResponse(HttpStatus status) {
    this.status = status;
  }

  public HttpResponse(HttpStatus status, String message) {
    this.status = status;
    this.message = message;
  }

  public HttpResponse(HttpStatus status, Object data) {
    this.status = status;
    this.data = data;
  }

  public HttpResponse(HttpStatus status, Object data, String message) {
    this.status = status;
    this.data = data;
    this.message = message;
  }

  public HttpResponse(HttpStatus status, Object data, int curPage, int pageSize, long totalCount) {
    this.status = status;
    this.data = data;
    this.curPage = curPage;
    this.pageSize = pageSize;
    this.totalCount = totalCount;
    long size = this.totalCount / this.pageSize;
    this.totalPage = (this.totalCount % this.pageSize == 0) ? size : size + 1;
  }

  public void setPageInfo(int curPage, int pageSize, long totalCount) {
    this.curPage = curPage;
    this.pageSize = pageSize;
    this.totalCount = totalCount;
    long size = this.totalCount / this.pageSize;
    this.totalPage = (this.totalCount % this.pageSize == 0) ? size : size + 1;
  }
}
